<?php

namespace App\Http\Requests\Auth\ResetPassword;

use App\Http\Requests\AbstractRequest;
use App\Models\AbstractUser;
use App\Models\User;

class SendLinkRequest extends AbstractRequest
{
    /**
     * @var AbstractUser
     */
    public $user;

    /**
     * 验证规则
     *
     * @return array
     */
    public function rules()
    {
        return [
            'email' => 'required|email'
        ];
    }

    /**
     * 验证邮箱地址是否存在
     *
     * @throws \Illuminate\Validation\ValidationException
     */
    protected function validate()
    {
        $user = User::where($this->only('email'))->first();

        if (!$user) {
            $this->validationException([
                'email' => ['邮箱地址 不存在']
            ]);
        }

        $this->user = $user;
    }
}
